using System.Collections.Generic;
using EntityFramework6.Services.Data;

namespace EntityFramework6._1Examples.Migrations
{
    using System.Data.Entity.Migrations;

    internal sealed class Configuration : DbMigrationsConfiguration<BookContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
            ContextKey = "EntityFramework6._1Examples.Data.BookContext";
        }

        protected override void Seed(BookContext context)
        {
            //  This method will be called after migrating to the latest version.
            //context.Database.ExecuteSqlCommand("Delete from Books");
            //context.Database.ExecuteSqlCommand("Delete from Authors");
            //context.Database.ExecuteSqlCommand("Delete from Publishers");
            //context.Database.ExecuteSqlCommand("Delete from BookAuthors");


            //// Add books
            //var books = new List<Book>()
            //{
            //    new Book()
            //    {
            //        Name = "VB.Net",
            //        ISBN = "1233445666",
            //        Price = 12,
            //        Category = Category.GeneralProgramming
            //    },
            //    new Book()
            //    {
            //        Name = "C#",
            //        Price = 14,
            //        Category = Category.OOP
            //    }
            //};

            //// Authors
            //var authors = new List<Author>();
            //authors.Add(new Author()
            //{
            //    Name = "Rahman Mahmoodi",
            //});
            //authors.Add(new Author()
            //{
            //    Name = "Hosha Mahmoodi"
            //});
            //foreach (var author in authors)
            //{
            //    context.Authors.AddOrUpdate(author);
            //}

            //// publisher
            //var publisher = new Publisher() {PublisherName = "P&L"};
            //context.Publishers.AddOrUpdate(publisher);

            //foreach (var book in books)
            //{
            //    // Add authors
            //    book.Authors = authors;

            //    // Add publisher
            //    book.Publisher = publisher;
   
            //    context.Books.AddOrUpdate(book);
            //}

            
            //context.SaveChanges();
        }
    }
}
